// pages/collage/collage.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    _num:1,
  },
  focus_click: function (e) {
    this.setData({
      _num: e.target.dataset.num
    })
  wx.showLoading({
  
  })
    var that = this;
    wx.request({
      url: app.data.Url + '/spell/userdefault',
      data: {
        uid: wx.getStorageSync('userInfo').uid,
        type: that.data._num
      },
      success: function (res) {
        that.setData({
          goods: res.data.data,

        })
        wx.hideLoading()
      }
    })
  },
  //拼团
  pingtuan:function(e){
    app.navTo('/pages/super/super')
  },
  //评价
  pingjia:function(e){
    var that=this;

    var url = '../reportEvaluate/reportEvaluate?orderid=' + e.currentTarget.dataset.id
    app.navTo(url)

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.showLoading({
     
    })
    wx.request({
      url: app.data.Url + '/spell/userdefault',
      data: {
        uid: wx.getStorageSync('userInfo').uid,
        type: that.data._num
      },
      success: function (res) {
        that.setData({
          goods: res.data.data,

        })
        
        wx.hideLoading()
      }
    })
  },
  buy:function(e){
    var order_no = e.currentTarget.dataset.id;
    var that=this;
  
    wx.request({
      url: app.data.Url + 'order/orderPayParams',
      data: {
        order_no: order_no,
        title: '智慧社区订单支付',
        uid: wx.getStorageSync('userInfo').uid
      },
      method: 'post',
      success: function (res) {
      
        wx.requestPayment({
          'timeStamp': res.data.data.weixin.timeStamp,
          'nonceStr': res.data.data.weixin.nonceStr,
          'package': res.data.data.weixin.package,
          'signType': 'MD5',
          'paySign': res.data.data.weixin.paySign,
          'success': function (res) {
        
            wx.showToast({
              title: '支付成功',
            })
            that.onShow();
          },
          'fail': function (res) {

          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  outbuy:function(e){
    var that=this;
    
    wx.showModal({
      title: '提示',
      content: '您确定取消订单吗',
      success:function(res){
        if(res.confirm==1){
          wx.showLoading({

          })
          wx.request({
            url: app.data.Url+'spell/delOrder',
            data:{
            
              order_no: e.currentTarget.dataset.id
            },
            method:'post',
            success:function(rs){
              wx.hideLoading();
              that.onShow();
              wx.showToast({
                title: '取消成功',
              })
            }
          })
        }
      }
    })
  }
})